import request from './request'

// 获取报名列表 (旧接口)
export const getRegistrationList = (params) => {
  return request.get('/registration/list', { params })
}

// 获取 EventRegistration 列表 (新接口，用于审核)
export const getEventRegistrationList = (params) => {
  return request.get('/registrations', { params })
}

// 获取报名详情
export const getRegistrationDetail = (id) => {
  return request.get(`/registration/${id}`)
}

// 创建报名
export const createRegistration = (data) => {
  return request.post('/registration', data)
}

// 更新报名
export const updateRegistration = (id, data) => {
  return request.put(`/registration/${id}`, data)
}

// 删除报名
export const deleteRegistration = (id) => {
  return request.delete(`/registration/${id}`)
}

// 批量删除报名
export const batchDeleteRegistrations = (ids) => {
  return request.delete('/registration/batch', { data: ids })
}

// 审核报名 (旧接口)
export const reviewRegistration = (id, data) => {
  return request.post(`/registration/${id}/review`, data)
}

// 审核报名 (新接口 - EventRegistration)
export const auditRegistration = (data) => {
  return request.post('/registrations/audit', data)
}

// 批量审核报名
export const batchAuditRegistrations = (auditList) => {
  return request.post('/registrations/audit/batch', auditList)
}

// 取消报名
export const cancelRegistration = (id) => {
  return request.post(`/registration/${id}/cancel`)
}

// 分配参赛号码
export const assignRaceNumber = (id, data) => {
  return request.post(`/registration/${id}/race-number`, data)
}

// 根据运动员ID获取报名信息
export const getRegistrationsByAthleteId = (athleteId) => {
  return request.get(`/registration/athlete/${athleteId}`)
}

// 根据项目ID获取已通过审核的报名信息
export const getApprovedRegistrationsByEventId = (eventId) => {
  return request.get(`/registration/event/${eventId}/approved`)
}

// 检查是否已报名
export const checkRegistration = (athleteId, eventId) => {
  return request.get('/registration/check', { 
    params: { athleteId, eventId } 
  })
}

// 导入报名
export const importRegistrations = (data) => {
  return request.post('/registration/import', data)
}

// 导出报名
export const exportRegistrations = (params) => {
  return request.get('/registration/export', { params, responseType: 'blob' })
}
